package com.bo.day20231201;


import java.util.*;
import java.util.Comparator;

/**
 * 比较器
 * 需要实现Comparator接口, compare (Student o1, Student o2)
 * 返回值>0：o1排在前面,o2排在后面
 * 返回值=0：说明o1和o2比较的值一样
 * 返回值<0：o2排在前面,o1排在后面
 *
 * @Author: gpb
 * @Date: 2023/12/1 16:38
 * @Description:
 */
public class ComparatorDemo {
    public static class Student {
        public String name;
        public int id;

        @Override
        public String toString () {
            return "Student{" +
                    "name='" + name + '\'' +
                    ", id=" + id +
                    ", age=" + age +
                    '}';
        }

        public int age;

        public Student (String name, int id, int age) {
            this.name = name;
            this.id = id;
            this.age = age;
        }


    }

    public static void main (String[] args) {
        List<Student> list = new ArrayList<>();
        Student a = new Student("a同学", 1, 18);
        Student b = new Student("b同学", 12, 21);
        Student c = new Student("c同学", 2, 20);
        list.add(a);
        list.add(b);
        list.add(c);
        list.sort(new StudentComparator());
        list.forEach(System.out::println);
    }

    public static class StudentComparator implements Comparator<Student> {
        @Override
        public int compare (Student o1, Student o2) {
            return 0;
        }
    }
}
